@echo off
setlocal

set SCRIPT_DIR=%~dp0
set BASE_DIR=%SCRIPT_DIR%..\\
cd /d "%BASE_DIR%"

set CONFIG_FILE=config/qwen32b_bird_dev.yaml
set TASK_ID=0

rem Parse command line arguments
:arg_loop
if "%1"=="" goto arg_done
if /i "%1"=="-Config" (
    set CONFIG_FILE=%2
    shift
)
if /i "%1"=="-TaskId" (
    set TASK_ID=%2
    shift
)
shift
goto arg_loop
:arg_done

set LOG_DIR=logs
mkdir "%LOG_DIR%" >nul 2>&1
for /f "tokens=1-4 delims=/ " %%a in ('date /t') do (set mydate=%%d%%b%%c)
for /f "tokens=1-2 delims=:" %%a in ('time /t') do (set mytime=%%a%%b)
set LOG_FILE=%LOG_DIR%\\run_evolutionary_one_task_%mydate%_%mytime%.log

echo Starting evolutionary_runner.py with config=%CONFIG_FILE% task-id=%TASK_ID%
echo Logging to: %LOG_FILE%

python -m alphasql.runner.evolutionary_runner %CONFIG_FILE% --task_id %TASK_ID% > %LOG_FILE% 2>&1

if %ERRORLEVEL% neq 0 (
    echo evolutionary_runner.py exited with code %ERRORLEVEL%. See log: %LOG_FILE% >&2
    exit /b %ERRORLEVEL%
)

echo Completed. See log: %LOG_FILE%
endlocal
